<template>
    <!-- 查询列表 -->
     <el-card class="search-card">
        <el-form :model="searchForm"  inline>
            <el-form-item label="报工类型">
                <el-select style="width: 120px;" v-model="searchForm.reportType" placeholder="报工类型" clearable>
                    <el-option label="自行报工" :value="1"/>
                    <el-option label="统一报工" :value="2"/>
                </el-select>
            </el-form-item>
            <el-form-item label="工作站名称">
                <el-input v-model="searchForm.workflowName" placeholder="工作站名称" clearable/>
            </el-form-item>
            <el-form-item label="生产工单编号">
                <el-input v-model="searchForm.productionOrderCode" placeholder="生产工单编号" clearable/>
            </el-form-item>
            <el-form-item label="产品物料编码">
                <el-input v-model="searchForm.productCode" placeholder="产品物料编码" clearable/>
            </el-form-item>
            <el-form-item label="报工人">
                <el-input v-model="searchForm.approverName" placeholder="记录人" clearable/>
            </el-form-item>
            <el-form-item label="状态">
                <el-select style="width: 120px;" v-model="searchForm.status" placeholder="状态" clearable>
                    <el-option label="草稿" :value="30"/>
                    <el-option label="已确认" :value="31"/>
                    <el-option label="已审核" :value="32"/>
                    <el-option label="已完成" :value="33"/>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="handleSearch" :icon="Search">查询</el-button>
                <el-button @click="resetSearchForm" :icon="Refresh">重置</el-button>
            </el-form-item>
        </el-form>
     </el-card>

     <!-- 展示信息的列表 -->
      <el-card class="table-card">
        <el-button @click="handleAdd">新增</el-button>
        <el-button @click="handelUpdate">修改</el-button>
        <el-button @click="handelDelete">删除</el-button>
        <el-table :data="feedbackForm" border stripe @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center"/>
            
            <el-table-column prop="reportCode" label="报工单号"/>
            <el-table-column prop="reportType" label="报工类型">
                <template #default="scope">
                    {{scope.row.reportType ==1?'统一报工':'自行报工' }}
                </template>
            </el-table-column>
            <el-table-column prop="workflowName" label="工作站"/>
            <el-table-column prop="processName" label="工序"/>
            <el-table-column prop="productionOrderCode" label="生产工单编号"/>
            <el-table-column prop="materialCode" label="产品物料编码"/>
            <el-table-column prop="materialName" label="产品物料名称"/>
            <el-table-column prop="materialSpecification" label="规格型号---"/>
            <el-table-column prop="unitName" label="单位---"/>
            <el-table-column prop="reportedQuantity" label="报工数量"/>
            <el-table-column prop="reporterName" label="报工人"/>
            <el-table-column prop="reportTime" label="报工时间"/>
            <el-table-column prop="approverName" label="审核人"/>
            <el-table-column prop="status" label="状态">
                <template #default="scope">
                    {{ scope.row.status == 30? '草稿': scope.row.status == 31?'已确认':scope.row.status == 32?'已审核':scope.row.status == 33?'已完成':'未知'}}
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template #default="scope">
                    <!-- <el-button size="small" :icon="Edit" v-if="status == 30">修改</el-button> -->
                    <el-button size="small" v-if="scope.row.status==31" @click="updatestatus(scope.row.id)">审核</el-button>
                    <el-button size="small" v-if="scope.row.status==30" @click="updatestatus1(scope.row.id)">确认</el-button>
                </template>
            </el-table-column>
        </el-table>
      </el-card>


      <!-- 新增的窗口 -->
       <el-dialog 
    title="新增生产报工记录"
    v-model="isShowAddWindow"
    width="80%"
    :close-on-click-modal="false">

    <el-form :model="addForm" label-width="100px">
        <el-row :gutter="20">
            <el-col :span="8">
                <el-form-item label="报工类型">
                    <el-select v-model="addForm.reportType" placeholder="请选择报工类型" style="width: 100%;">
                        <el-option label="自行报工" :value="1"/>
                        <el-option label="统一报工" :value="2"/>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="报工单号">
                    <el-input v-model="addForm.reportCode" placeholder="系统自动生成" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="生产工单">
                    <el-input v-model="addForm.productionOrderCode" placeholder="请选择生产工单" disabled>
                        <template #append>
                            <el-button :icon="Search" @click="showProductionOrderDialog"/>
                        </template>
                    </el-input>
                </el-form-item>
            </el-col>

            <el-col :span="8">
                <el-form-item label="工作站">
                    <el-input v-model="addForm.workflowName" placeholder="请选择工作站" disabled>
                        <template #append>
                            <el-button :icon="Search" @click="showWorkflowDialog"/>
                        </template>
                    </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="生产任务">
                    <el-input v-model="addForm.taskCode" placeholder="请选择生产任务" disabled>
                        <template #append>
                            <el-button :icon="Search" @click="showTasklistDialog"/>
                        </template>
                    </el-input>
                </el-form-item>
            </el-col>
             <el-col :span="8">
                <el-form-item label="报工数量">
                    <el-input-number v-model="addForm.reportedQuantity" :min="1" placeholder="请输入报工数量" style="width: 100%;" />
                </el-form-item>
            </el-col>
        </el-row>

        <el-divider content-position="left">产品信息</el-divider>

        <el-row :gutter="20">
            <el-col :span="6">
                <el-form-item label="产品编码">
                    <el-input v-model="addForm.materialCode" placeholder="产品编码" disabled/>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="产品名称">
                    <el-input v-model="addForm.materialName" placeholder="产品名称" disabled/>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="规格型号">
                    <el-input v-model="addForm.materialSpecification" placeholder="规格型号" disabled/>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="单位">
                    <el-input v-model="addForm.unitName" placeholder="单位" disabled/>
                </el-form-item>
            </el-col>
        </el-row>

        <el-divider content-position="left">人员与时间</el-divider>

        <el-row :gutter="20">
            <el-col :span="8">
                <el-form-item label="报工人">
                    <el-input v-model="addForm.reporterName" placeholder="请选择报工人" disabled>
                        <template #append>
                            <el-button :icon="Search" @click="showUserDialog"/>
                        </template>
                    </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="审核人">
                    <el-input v-model="addForm.approverName" placeholder="请选择审核人" disabled>
                        <template #append>
                            <el-button :icon="Search" @click="showUserDialog2"/>
                        </template>
                    </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="报工时间">
                    <el-date-picker
                        v-model="addForm.reportTime"
                        type="datetime"
                        placeholder="请选择报工时间"
                        style="width: 100%;"
                        format="YYYY-MM-DD HH:mm:ss"
                        value-format="YYYY-MM-DD HH:mm:ss"
                    />
                </el-form-item>
            </el-col>
        </el-row>

        <el-row>
            <el-col :span="24">
                 <el-form-item label="备注">
                    <el-input v-model="addForm.remark" type="textarea" :rows="3" placeholder="请输入备注"/>
                </el-form-item>
            </el-col>
        </el-row>
    </el-form>

    <template #footer>
        <div class="dialog-footer">
            <el-button @click="isShowAddWindow = false">取 消</el-button>
            <el-button type="primary" @click="submitForm">确 认</el-button>
        </div>
    </template>
</el-dialog>
    <!-- 编辑的窗口 -->
           <el-dialog 
    title="编辑生产报工记录"
    v-model="isShowUpdateWindow"
    width="80%"
    :close-on-click-modal="false">

    <el-form :model="editForm" label-width="100px">
        <el-row :gutter="20">
            <el-col :span="8">
                <el-form-item label="报工类型">
                    <el-select v-model="editForm.reportType" placeholder="请选择报工类型" style="width: 100%;">
                        <el-option label="自行报工" :value="1"/>
                        <el-option label="统一报工" :value="2"/>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="报工单号">
                    <el-input v-model="editForm.reportCode" placeholder="系统自动生成" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="生产工单">
                    <el-input v-model="editForm.productionOrderCode" placeholder="请选择生产工单" disabled>
                        <template #append>
                            <el-button :icon="Search" @click="showProductionOrderDialog"/>
                        </template>
                    </el-input>
                </el-form-item>
            </el-col>

            <el-col :span="8">
                <el-form-item label="工作站">
                    <el-input v-model="editForm.workflowName" placeholder="请选择工作站" disabled>
                        <template #append>
                            <el-button :icon="Search" @click="showWorkflowDialog"/>
                        </template>
                    </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="生产任务">
                    <el-input v-model="editForm.taskCode" placeholder="请选择生产任务" disabled>
                        <template #append>
                            <el-button :icon="Search" @click="showTasklistDialog"/>
                        </template>
                    </el-input>
                </el-form-item>
            </el-col>
             <el-col :span="8">
                <el-form-item label="报工数量">
                    <el-input-number v-model="editForm.reportedQuantity" :min="1" placeholder="请输入报工数量" style="width: 100%;" />
                </el-form-item>
            </el-col>
        </el-row>

        <el-divider content-position="left">产品信息</el-divider>

        <el-row :gutter="20">
            <el-col :span="6">
                <el-form-item label="产品编码">
                    <el-input v-model="editForm.materialCode" placeholder="产品编码" disabled/>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="产品名称">
                    <el-input v-model="editForm.materialName" placeholder="产品名称" disabled/>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="规格型号">
                    <el-input v-model="editForm.materialSpecification" placeholder="规格型号" disabled/>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="单位">
                    <el-input v-model="editForm.unitName" placeholder="单位" disabled/>
                </el-form-item>
            </el-col>
        </el-row>

        <el-divider content-position="left">人员与时间</el-divider>

        <el-row :gutter="20">
            <el-col :span="8">
                <el-form-item label="报工人">
                    <el-input v-model="editForm.reporterName" placeholder="请选择报工人" disabled>
                        <template #append>
                            <el-button :icon="Search" @click="showUserDialog"/>
                        </template>
                    </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="审核人">
                    <el-input v-model="editForm.approverName" placeholder="请选择审核人" disabled>
                        <template #append>
                            <el-button :icon="Search" @click="showUserDialog2"/>
                        </template>
                    </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="报工时间">
                    <el-date-picker
                        v-model="editForm.reportTime"
                        type="datetime"
                        placeholder="请选择报工时间"
                        style="width: 100%;"
                        format="YYYY-MM-DD HH:mm:ss"
                        value-format="YYYY-MM-DD HH:mm:ss"
                    />
                </el-form-item>
            </el-col>
        </el-row>

        <el-row>
            <el-col :span="24">
                 <el-form-item label="备注">
                    <el-input v-model="editForm.remark" type="textarea" :rows="3" placeholder="请输入备注"/>
                </el-form-item>
            </el-col>
        </el-row>
    </el-form>

    <template #footer>
        <div class="dialog-footer">
            <el-button @click="isShowAddWindow = false">取 消</el-button>
            <el-button type="primary" @click="submitForm">确 认</el-button>
        </div>
    </template>
</el-dialog>

          <!-- 选择工作台 -->
    <el-dialog v-model="isWorkflowShow"
        title='选择工作站'
        :close-on-click-modal="false"
        >
        <el-table :data="workflowList" @row-click="handleSelect" v-if="isWorkflowShow">
            <el-table-column label="工作台编码" prop="workflowCode"/> 
            <el-table-column label="工作台名称" prop="workflowName"/> 
            <el-table-column label="状态" prop="status">
                <template #default="scope">
                    <!-- scop.row代表当前一行 -->
                    {{scope.row.status ==  1?'启用':'禁用'}}
                </template>
            </el-table-column>
            <el-table-column label="描述" prop="workflowDescription"/> 
            <el-table-column label="备注" prop="remarks"/> 
        </el-table>
    </el-dialog>

    <!-- 选择生产任务 -->
     <el-dialog v-model="isShowProductionOrder"
        title="选择生产任务"
        :close-on-click-modal="false"
        width="80%"
        >
        <el-table :data="productionOrderList" @row-click="handleSelect" v-if="isShowProductionOrder">
            <el-table-column label="工单编号" prop="productionOrderCode"/>
            <el-table-column label="工单名称" prop="productionOrderName"/>
            <el-table-column label="工单类型" prop="productionOrderType">
                <template #default="scope">
                    {{ scope.row.productionOrderType == 1? '自产':scope.row.productionOrderType == 2?'外协':'外购'}}
                </template>
            </el-table-column>
            <el-table-column label="工单来源" prop="productionOrderSource">
                <template #default="scope">
                    {{ scope.row.productionOrderSource == 1?'客户订单':'库存备货' }}
                </template>
            </el-table-column>
            <el-table-column prop="orderCode" label="订单编号" />
            <el-table-column prop="material.code" label="产品/物料编号" />
            <el-table-column prop="material.name" label="产品/物料名称" />
            <el-table-column prop="material.specification" label="规格" />
            <el-table-column prop="material.unit.name" label="单位" />
            <el-table-column prop="productionOrderQuantity" label="工单数量" />
            <el-table-column prop="customer.code" label="客户编号" />
            <el-table-column prop="customer.name" label="客户名称" />
            <el-table-column prop="requestDate" label="需求日期" />
            <el-table-column prop="status" label="状态">
                 <template #default="scope">
                    {{ scope.row.status == 30?'草稿':scope.row.status == 31?'已确认':scope.row.status == 32?'已审核':scope.row.status == 33?'已完成':'未知状态'}}
                </template>
            </el-table-column>
        </el-table>
        </el-dialog>

        <!-- 选择任务（tasklist） -->
         <el-dialog
         title="选择任务"
         v-model="isShowTasklist"
         :close-on-click-modal="false"
        width="80%">
            <el-table v-if="isShowTasklist" :data="tasklistList" @row-click="handleSelect">
                <el-table-column label="任务编号" prop="taskCode"/>
                <el-table-column label="任务名称" prop="taskName"/>
                <el-table-column label="工作站编号" prop="workstationCode"/>
                <el-table-column label="工作站名称" prop="workstationName"/>
                <el-table-column label="排产数量" prop="scheduledQuantity"/>
                <el-table-column label="已生产数量" prop="producedQuantity"/>
                <el-table-column label="开始生产时间" prop="startTime"/>
                <el-table-column label="生产时长（分钟）" prop="productionDuration"/>
                <el-table-column label="预计完成时间" prop="estimatedCompletionTime"/>
                <el-table-column label="显示颜色" prop="displayColor">
                    <template v-slot="scope">
                    <el-color-picker v-model="scope.row.displayColor" disabled />
                    </template>
                </el-table-column>
            </el-table> 
        </el-dialog>

        <!-- 选择人员 -->
         <el-dialog
         title="用户列表"
         v-model="isShowUserList"
         :close-on-click-modal="false"
         width="80%">
         <el-table v-if="isShowUserList" :data="UserList" @row-click="handleSelect">
            <el-table-column prop="id" label="ID" width="80" />
            <el-table-column prop="username" label="用户名" />
            <el-table-column prop="fullName" label="姓名"/>
            <el-table-column prop="email" label="邮箱" />
            <el-table-column prop="remark" label="角色"/>
            <el-table-column prop="email" label="邮箱"/>
            <el-table-column prop="phone" label="电话"/>
         </el-table>
         </el-dialog>
</template>

<script setup>
import { ref, onMounted } from "vue";
// UI组件：从 element-plus 导入图标、消息提示和确认对话框
import { Plus, Search, Refresh, Edit, Delete, MessageBox, Check } from '@element-plus/icons-vue'
import { ElButton, ElMessage, ElMessageBox } from "element-plus";
import { addFeedbackList, batchDeleteFeedback, deleteFeedback, getfeedbackList, queryFeedbackById, updateFeedbackById } from "@/api/feedback";
import { getWorkflowPage } from "@/api/workflow";
import { getProductionOrderList } from "@/api/production-order";
import { getTaskList } from "@/api/taskList";
import { getMaterialByCode, getMaterialPage } from "@/api/material";
import { getUnitPage } from "@/api/unit";
import { getCategoryById, getCategoryPage } from "@/api/material-category";
import { getUserList } from "@/api/user";

//控制窗口显示的
const isShowAddWindow = ref(false);//新增窗口的展示
const isWorkflowShow = ref(false);//选择工作台的显示
const isShowProductionOrder = ref(false);//控制任务列表的显示
const isShowTasklist = ref(false);//控制任务列表的额显示
const isShowUserList = ref(false);//控制用户列表的显示
const isShowUpdateWindow = ref(false);//控制修改信息列表
//查询列表的数据
const getSearchForm =()=>({
    reportType:null,workflowName:"",
    productionOrderCode:"",productCode:"",
    productName:"",reporterName:"",
    approverName:"",status:null
});
//新增列表的数据
const getAddFrom =()=>({
    reportType:null,reportCode:"",productionOrderId:null,
    productionOrderCode:"",workflowName:"",
    taskCode:"",materialCode:"",materialName:"",
    unitName:"",materialSpecification:"",
    reportedQuantity:"",reporterName:"",
    reportTime:"",approverName:"",
    remark:""
});

//workflow的内容表单
const getWorkflowList=()=>({
    id:null,workflowCode:"",workflowName:"",
    status:null,workflowDescription:"",remarks:"",
    createTime:"",createBy:"",updateTime:"",
    updateBy:"",deleteFlag:""
});
//任务列表的内容表单
const getProdcutionOrderList=()=>({
    productionOrderCode:"",productionOrderName:"",
    productionOrderSource:"",materialCode:"",
    materialName:"",customerCode:"",
    productionOrderType:"",status:""
});
const getTaskListForm=()=>({
    productionOrderId:null,processId:null,workflowId:null
})
const getCategory=()=>({
    id:null,code:"",name:"",parentId:null,description:"",
    status:null,createTiem:"",updateTime:""
})
const getUser=()=>({
    id:null,username:"",password:"",
    fullName:"",email:"",phone:"",status:"",
    avatar:"",lastLoginTime:"",
    createdBy:null,createdTime:"",
    updatedBy:null,updateTiem:"",
    remark:"",deleteFlag:null
})


// 查询表单
const searchForm = ref(getSearchForm());
//展示表格的数据
const feedbackForm = ref([]);
//新增列表的数据
const addForm = ref(getAddFrom());
const workflowFrom = ref(getWorkflowList());//负责查询workflow的信息
const workflowList = ref([]);//获得workflow的信息
const productionOrderForm = ref(getProdcutionOrderList());//获取查询得到的产品订单信息
const productionOrderList = ref([]);//查詢获得的产品订单信息
const tasklistFrom = ref(getTaskListForm());//任务列表表单
const tasklistList = ref([]);//查询获得的任务列表信息
const categoryFrom = ref(getCategory());//物料分类查询
const UserForm = ref(getUser());//查询用户信息
const UserList = ref();//存储用户信息
const selectedTasks = ref([]);//存储用户选择的信息
const editForm = ref(getAddFrom());//要修改的信息
// -----------------------------
// 处理查询
const handleSearch=()=>{
    getfeedbackList(
        searchForm.value.reportType,
        searchForm.value.workflowName,
        searchForm.value.productionOrderCode,
        searchForm.value.productCode,
        searchForm.value.productName,
        searchForm.value.reporterName,
        searchForm.value.approverName,
        searchForm.value.status
    ).then(res=>{
        feedbackForm.value =res.data.list;
        console.log(feedbackForm.value);
        //之后写分页
    })
}

const handleAdd=()=>{
    isShowAddWindow.value = true;
}
const handelUpdate=()=>{
    
    
    if(selectedTasks.value.length!=1){
        ElMessage.warning('请选择一项进行编辑！');
        return;
    }
    const selectedItem = selectedTasks.value[0];

    editForm.value = JSON.parse(JSON.stringify(selectedItem));

    // 4. 打开编辑弹窗
    isShowUpdateWindow.value = true;

}


const handelDelete=()=>{
    if(selectedTasks.value.length<1){
        ElMessage.warning('请选择一项进行删除！');
        return;
    }
    ElMessageBox.confirm(
        `您确定要删除选中的 ${selectedTasks.value.length} 条记录吗？`,
        '警告',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(() => {
    if(selectedTasks.value.length==1){
            const selectItem = selectedTasks.value[0];
            deleteFeedback(selectItem.id).then(res=>{
                ElMessage.success("删除成功");
                handleSearch();
            })
            
    }
    if(selectedTasks.value.length>1){
        const idsToDelete = selectedTasks.value.map(item => item.id);
        batchDeleteFeedback(idsToDelete).then(res=>{
            ElMessage.success("删除成功");
                handleSearch();
        })
    }
    }).catch(() => {
        // 用户点击“取消”后的回调，可以什么都不做
        ElMessage.info('已取消删除');
    });
}
//提交表单
const submitForm=()=>{
    if(isShowAddWindow.value){
        addFeedbackList(addForm.value
        ).then(res=>{
            ElMessage.success("添加成功");
            isShowAddWindow.value= false;
        })
    }
    if(isShowUpdateWindow.value){
        updateFeedbackById(editForm.value).then(res=>{
            ElMessage.success("修改成功");
            isShowUpdateWindow.value =false;
            handleSearch(); //
        })
        
    }
}
//处理重置
const resetSearchForm=()=>{
    searchForm.value = (getSearchForm());
}

//选择工作台
const handleSelect = (selectedRow) => {
    // 确定当前应该更新哪个表单模型
    let currentForm = isShowAddWindow.value ? addForm : editForm;

    // --- 处理选择工作站 ---
    if (isWorkflowShow.value) {
        currentForm.value.workflowId = selectedRow.id;
        currentForm.value.workflowCode = selectedRow.workflowCode;
        currentForm.value.workflowName = selectedRow.workflowName;   
        isWorkflowShow.value = false;
        return; // 处理完后直接返回
    }

    // --- 处理选择生产工单 ---
    if (isShowProductionOrder.value) {
        currentForm.value.productionOrderId = selectedRow.id;
        currentForm.value.productionOrderCode = selectedRow.productionOrderCode;
        currentForm.value.materialCode = selectedRow.materialCode;
        currentForm.value.materialName = selectedRow.material.name;
        currentForm.value.unitName = selectedRow.material.unit.name;

        //... (你根据 categoryId 查询规格的逻辑)
        getCategoryById(selectedRow.material.categoryId).then(res=>{
            if (res.data) {
                currentForm.value.materialSpecification = res.data.name; 
            } else {
                ElMessage.warning("未查询到物料分类信息！");
            }
        });
        isShowProductionOrder.value = false;
        return;
    }

    // --- 处理选择生产任务 ---
    if (isShowTasklist.value) {
        currentForm.value.taskListId = selectedRow.id;
        currentForm.value.taskCode = selectedRow.taskCode;
        isShowTasklist.value = false;
        return;
    }

    // --- 处理选择用户 (报工人/审核人) ---
    if (isShowUserList.value) {
        if(reptortDialog.value){
            currentForm.value.reporterId = selectedRow.id;
            currentForm.value.reporterName = selectedRow.fullName || selectedRow.username;
            reptortDialog.value = false;
        }
        if(approverDialog.value){
            currentForm.value.approverId = selectedRow.id;
            currentForm.value.approverName = selectedRow.fullName || selectedRow.username;
            approverDialog.value = false;
        }
        isShowUserList.value = false;
    }
}
//-----------------
//
const showWorkflowDialog=()=>{//显示工作台弹窗
    isWorkflowShow.value =true;
    SearchWorkflow();
}
const SearchWorkflow=()=>{
    getWorkflowPage(
        1,
        10,
        workflowFrom.value
    ).then(res=>{
        workflowList.value = res.data.list;
       // pagination.value.total = res.data.total;
    })
}
//产品订单弹窗显示
const showProductionOrderDialog=()=>{
    isShowProductionOrder.value = true;
    SearchProductionOrder();
}
//查看生产工单信息
const SearchProductionOrder=()=>{
    getProductionOrderList(
        productionOrderForm.value
    ).then(res=>{
        productionOrderList.value = res.data.list;
    })

}
//任务弹窗显示
const showTasklistDialog=()=>{
    isShowTasklist.value =true;
    SearchTasklistList();
}

const SearchTasklistList=()=>{
    getTaskList(tasklistFrom.value.productionOrderId,
        tasklistFrom.value.processId,
        tasklistFrom.value.workflowId
    ).then(res=>{
        tasklistList.value = res.data.list;
    })
}
//----------------------
const　reptortDialog= ref(false);
const showUserDialog=()=>{
    isShowUserList.value =true;
    reptortDialog.value = true;
    searchUserList(); 
}
const approverDialog= ref(false);
const showUserDialog2=()=>{
    isShowUserList.value =true;
    approverDialog.value = true;
    searchUserList(); 
}

const searchUserList = () => {
    // 1. 将分页信息和查询条件合并成一个参数对象
    const params = {
        pageNum: 1,
        size: 10,
        ...UserForm.value // 使用 .value 获取 ref 的实际对象，并展开到 params 中
    };
    //遍历 params 对象，移除值为空字符串的属性
     Object.keys(params).forEach(key => {
        if (params[key] === '' || params[key] === null || params[key] === undefined) {
            delete params[key];
        }
    });
    // 2. 使用这个 params 对象来调用 API
    getUserList(params).then(res => {
        UserList.value = res.data; 
    }).catch(err => {
        ElMessage.error("获取用户列表失败");
        console.error(err);
    });
}
//**** */
// 多选框框
const handleSelectionChange = (selection)=>{
   selectedTasks.value = selection;
}
//**** */
//*** */
const updatestatus1=(id)=>{
    ElMessageBox.confirm(
        '你确定要将此记录的状态更新为“已确认”吗？',
        '状态确认',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(() => {

        queryFeedbackById(id).then(res => {
            let recordToUpdate = res.data;

            recordToUpdate.status = 31;

            updateFeedbackById(recordToUpdate).then(res => {
                ElMessage.success("状态更新成功！");
                handleSearch(); // 刷新列表
            }).catch(err => {
                ElMessage.error("更新失败");
                console.error(err);
            });
        }).catch(err => {
            ElMessage.error("获取记录详情失败，无法更新");
            console.error(err);
        });

    }).catch(() => {
        ElMessage.info('已取消操作');
    });
}
const updatestatus =(id)=>{
 ElMessageBox.confirm(
        '你确定要将此记录的状态更新为“已审核”吗？',
        '状态确认',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(() => {

        queryFeedbackById(id).then(res => {
            let recordToUpdate = res.data;
            recordToUpdate.status = 32;
            updateFeedbackById(recordToUpdate).then(res => {
                ElMessage.success("状态更新成功！");
                handleSearch(); // 刷新列表
            }).catch(err => {
                ElMessage.error("更新失败");
                console.error(err);
            });
        }).catch(err => {
            ElMessage.error("获取记录详情失败，无法更新");
            console.error(err);
        });

    }).catch(() => {
        ElMessage.info('已取消操作');
    });
}
//----------
onMounted(()=>{
handleSearch();
})
    
</script>

<style scoped>

</style>